<?php
/**
 * Created by PhpStorm.
 * User: fenfen
 * Date: 2017/1/3
 * Time: 17:47
 */

namespace backend\controllers;
use bc\controller\BackendController;
use bc\model\OrderbindMode;
use bc\model\UserreportModel;
use bc\model\ReportModel;

class ReportController extends BackendController
{
    public $aview;
    public function actionIndex()
    {
        return $this->render("index");
    }

    public function actionReport()
    {
        //获取标题数据
//        $bind_no=$this->post('bind_no');
        $bind_no=$this->get('bind_no');
        //根据bind_no获取产品id
        $OrderbindM= new OrderbindMode();
        $OrderbindM->autoId='bind_no';
        $OrderbindD=$OrderbindM->getRowById($bind_no);
        $product_id=$OrderbindD['product_id'];
        $UserreportData=array();
        if(empty($bind_no )||empty($product_id ))
        {
        }else {
            $UserreportM = new UserreportModel();
            $UserreportData = $UserreportM->getInfoFromBindno($product_id, $bind_no);
        }
        $row['report_1_share']=isset($UserreportData['report_1_share']) ? $UserreportData['report_1_share'] : '';
        $row['report_2_share']=isset($UserreportData['report_2_share']) ? $UserreportData['report_2_share'] : '';
        $row['report_3_share']=isset($UserreportData['report_3_share']) ? $UserreportData['report_3_share'] : '';
        $row['report_4_share']=isset($UserreportData['report_4_share']) ? $UserreportData['report_4_share'] : '';
        $row['report_5_share']=isset($UserreportData['report_5_share']) ? $UserreportData['report_5_share'] : '';
        $row['report_1_text']=isset($UserreportData['report_1_share']) ? $UserreportData['report_1_share'] : '';
        $row['report_2_text']=isset($UserreportData['report_2_share']) ? $UserreportData['report_2_share'] : '';
        $row['report_3_text']=isset($UserreportData['report_3_share']) ? $UserreportData['report_3_share'] : '';
        $row['report_4_text']=isset($UserreportData['report_4_share']) ? $UserreportData['report_4_share'] : '';
        $row['report_5_text']=isset($UserreportData['report_5_share']) ? $UserreportData['report_5_share'] : '';
        $row['bind_no']=$bind_no;
        $row['product_id']=$product_id;
        $this->layout=false;
        return $this->render ( 'report',$row );
    }

    public function actionAjaxareportinfo()
    {
        $reportM = new ReportModel();
        //获取标题数据
        $bind_no=$this->get('bind_no');
        //根据bind_no获取产品id
        $OrderbindM= new OrderbindMode();
        $OrderbindM->columns='bc_order_bind.user_id as ouser_id,bc_order_bind.product_id as oproduct_id';
        $OrderbindD=$OrderbindM->getRow(['bind_no'=>$bind_no]);
        $user_id=$OrderbindD[0]['ouser_id'];
        $product_id = $OrderbindD[0]['oproduct_id'];
        $reportinfo=$reportM -> getReportInfoTemp($user_id,$bind_no,$product_id);
        $data=array(
                "msg"=>"获取成功",
	            "result"=>1,
	            "data"=>$reportinfo
        );
        $json_data=json_encode($data,JSON_UNESCAPED_UNICODE);
        $jsoncallback = htmlspecialchars($_REQUEST ['jsoncallback']);//把预定义的字符转换为 HTML 实体。
        echo $jsoncallback . "(" . $json_data . ")";
    }

    //报告模板
    public function actionBreport()
    {
        return $this->render ( 'breport' );
    }

}